package com.fulong.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fulong.entity.*;
import com.fulong.service.*;
import com.fulong.web.webconfig.UserStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fulong.common.utils.PageUtils;
import com.fulong.common.utils.R;



/**
 * 
 *
 * @author fulong
 * @email ${email}
 * @date 2022-04-09 10:29:46
 */
@RestController
@RequestMapping("/devicepayinfo")
public class DevicePayInfoController {
    @Autowired
    private DevicePayInfoService devicePayInfoService;
    @Autowired
    private DeviceLendRecordService deviceLendRecordService;
    @Autowired
    private DeviceBaiseInfoService deviceBaiseInfoService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = devicePayInfoService.queryPage(params);
        return R.ok().put("page", page);
    }
    @RequestMapping("/getInfo")
    public R getApproverInfo(@RequestBody Map<String, Object> params){
//        PageUtils page = devicePayInfoService.queryPage(params);
        Map<String, Object> info = devicePayInfoService.getBuyRecordInfo(params.get("id").toString());
        return R.ok().put("info", info);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		DevicePayInfoEntity devicePayInfo = devicePayInfoService.getById(id);

        return R.ok().put("devicePayInfo", devicePayInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DevicePayInfoEntity devicePayInfo){
        devicePayInfo.setTimes(new Date());
		devicePayInfoService.save(devicePayInfo);
        /*
        * 发动审批
        * */
        DeviceLendRecordEntity deviceLendRecordEntity = new DeviceLendRecordEntity();
        deviceLendRecordEntity.setDeviceid(devicePayInfo.getId());
        deviceLendRecordEntity.setStatus(10);
        deviceLendRecordEntity.setLenddate(devicePayInfo.getTimes());
        deviceLendRecordEntity.setUserid(UserStatus.getParam().getId());
        deviceLendRecordEntity.setApproverid(devicePayInfo.getApproverid());
        deviceLendRecordService.save(deviceLendRecordEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DevicePayInfoEntity devicePayInfo){
		devicePayInfoService.updateById(devicePayInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		devicePayInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
